package design.proxy.two;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * jdk动态代理，要求被代理类至少实现一个接口
 *
 * @Author: zhenzhong.wang
 * @Time: 2018/4/10 10:47
 */
public class JDKProxy {

  private Object target;

  public JDKProxy(Object target) {
    this.target = target;
  }

  public Object getProxyInstance() {
    return Proxy.newProxyInstance(
        target.getClass().getClassLoader(),
        target.getClass().getInterfaces(),
        new InvocationHandler() {
          @Override
          public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if (method.getName().equals("")) {
            }
            Object invoke = method.invoke(target, args);
            System.out.println("after JDKProxyFactory");
            return invoke;
          }
        }
    );
  }
}
